package com.training.regex;

public class RegexDemo02 {
	public static void main(String[] args) {
		String str = "123456";
		String str2 = "";
		String str3 = "1234567";
		
		String regex = "[0-9]";
		String regex2 = "[0-9][0-9][0-9][0-9][0-9][0-9]";
		
		String regex3 = "[0-9]+";//匹配前面的子表达式一次或者多次
		String regex4 = "[0-9]*";//匹配前面的子表达式0次或者多次
		String regex5 = "[0-9]?";//匹配前面的子表达式0次或者1次
		String regex6 = "[0-9]{6}";//匹配前面的子表达式正好6次
		String regex7 = "[0-9]{6,}";//匹配前面的子表达式至少6次
		String regex8 = "[0-9]{6,8}";//匹配前面的子表达式至少6次，至多8次
		
		System.out.println(str.matches(regex));//因为只匹配了第一个，所以为false
		System.out.println(str.matches(regex2));
		
		System.out.println(str.matches(regex3));
		System.out.println(str2.matches(regex4));
		System.out.println(str2.matches(regex5));
		
		System.out.println(str.matches(regex6));
		System.out.println(str3.matches(regex6));
		System.out.println(str3.matches(regex7));
		System.out.println(str.matches(regex8));
		System.out.println(str3.matches(regex8));
		System.out.println("------------------------------------------");
		
		String strl = "a123";
		String regexl = "([a-z]|[0-9])[0-9]+";//首位为[a-z]或[0-9]，后面是[0-9],()代表分组
		
		System.out.println(strl.matches(regexl));
	}
}
